import threading


class ServiceManager:
    """统一管理所有后台服务"""

    # 使用类变量实现单例
    _instance = None
    _lock = threading.Lock()

    def __new__(cls):
        with cls._lock:
            if cls._instance is None:
                cls._instance = super().__new__(cls)
                cls._instance._initialized = False
            return cls._instance

    def __init__(self):
        if not self._initialized:
            self._started = False
            self._initialized = True

    def start_all(self):
        if not self._started:
            self._started = True
            print("服务已启动")

    def stop_all(self):
        if self._started:
            self._started = False
            print("服务已停止")


# 全局单例
service_manager = ServiceManager()